#!/bin/bash

# 检查所有服务状态

echo "=========================================="
echo "检查服务状态"
echo "=========================================="

# 检查是否在项目根目录
if [ ! -f "fastapi_app.py" ] || [ ! -d "services" ]; then
    echo "错误: 请从项目根目录执行此脚本"
    echo "正确用法: ./deploy/check_services.sh"
    echo "当前目录: $(pwd)"
    exit 1
fi

# 检查原始FastAPI服务 (8080)
echo -n "原始FastAPI服务 (8080): "
if curl -s http://localhost:8080/health > /dev/null 2>&1; then
    echo "✓ 运行中"
else
    echo "✗ 未运行"
fi

# 检查对话服务V2 (8001)
echo -n "对话服务V2 (8001): "
if curl -s http://localhost:8001/health > /dev/null 2>&1; then
    echo "✓ 运行中"
else
    echo "✗ 未运行"
fi

# 检查元素提取API (8002)
echo -n "元素提取API (8002): "
if curl -s http://localhost:8002/docs > /dev/null 2>&1; then
    echo "✓ 运行中"
else
    echo "✗ 未运行"
fi

echo "=========================================="
echo "端口占用情况:"
echo "=========================================="
lsof -i :8080 2>/dev/null | grep LISTEN || echo "端口 8080: 未占用"
lsof -i :8001 2>/dev/null | grep LISTEN || echo "端口 8001: 未占用"
lsof -i :8002 2>/dev/null | grep LISTEN || echo "端口 8002: 未占用" 